package extration;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

public class Message {
	
	private String id;
	private String sentiment;
	private String topic;
	//Le mot et son occurence dans cd Message
	private HashMap<Mot,Integer> listeMot;
	
	public Message(){
		this.id ="";
		this.sentiment = "";
		this.topic ="";
		this.listeMot = new HashMap<Mot,Integer>();
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Message(String s, String t, HashMap<Mot,Integer> m){
		this.sentiment = s;
		this.topic =t;
		this.listeMot = m;
	}
	
	public String getSentiment() {
		return sentiment;
	}
	public void setSentiment(String sentiment) {
		this.sentiment = sentiment;
	}
	public String getTopic() {
		return topic;
	}
	public void setTopic(String topic) {
		this.topic = topic;
	}
	public HashMap<Mot,Integer> getListeMot() {
		return listeMot;
	}
	public void setListeMot(HashMap<Mot,Integer> listeMot) {
		this.listeMot = listeMot;
	}
	
	public void addMot(Mot m, String polarite){
		if(listeMot.containsKey(m)){
			int nb = listeMot.get(m);
			listeMot.put(m, ++nb);
		}
		else{
			listeMot.put(m, 1);
			m.addNbMessage();
			if(polarite!=null)
				m.addNbMsgPolarite(polarite);
		}
	}
	
	//Enlever les mots
	public void removeMot(ArrayList<Mot> liste){
		for(Mot m : liste){
			this.listeMot.remove(m);
		}
	}
	public String toString(){
		String chaine="********************************* Message n "+ id + " *********************************\n";	
		for (Entry<Mot,Integer> hm : listeMot.entrySet()){
			Mot m = hm.getKey();
			int nbOccDoc = hm.getValue();
			chaine+=m.getChaine() + "\n";
			chaine += "-----Stats khi--------\n";
			/*for(Entry<String,Double> tab : m.getKhiPolarite().entrySet()){
				chaine+= "=>" + tab.getKey() + " khi = " + tab.getValue() +"\n";
			}*/
			chaine+= "=>" + Data.POSITIVE + " Occ = " +  m.getOccPolarite(Data.POSITIVE) +"\n";
			chaine+= "=>" + Data.NEGATIVE + " Occ = " +  m.getOccPolarite(Data.NEGATIVE) +"\n";
			chaine+= "=>" + Data.NEUTRAL + " Occ = " +  m.getOccPolarite(Data.NEUTRAL) +"\n";
			chaine+= "=>" + Data.IRRELEVANT + " Occ = " +  m.getOccPolarite(Data.IRRELEVANT) +"\n";
			chaine += "----------FIN MOT--------\n";
			
		}
		chaine+="******************************************** Fin message ****************************\n";	
		
		return chaine;
	}
	

}
